<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/decorators/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>${pageTitle}</title>
<script type="text/javascript" src="${appPath}/js/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="${appPath}/js/jquery-ui-1.9.2.custom.min.js"></script>
<script type="text/javascript" src="${appPath}/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${appPath}/js/locale/easyui-lang-zh_TW.js"></script>
<!-- default -->
<link rel="stylesheet" type="text/css" id="ui_css" href="${appPath}/themes/metro-blue/easyui2.css" />
<link rel="stylesheet" type="text/css" href="${appPath}/css/css2.css" />
<link rel="stylesheet" type="text/css" id="icon_css" href="${appPath}/themes/icon.css" />
</head>
<body style="padding: 30px;">
	<form:form method="post" id="filesForm" enctype="multipart/form-data"
		modelAttribute="filesForm" action="${appPath}/files/save.json">
		<form:hidden id="sessionNo" path="sessionNo" />
		<table width="530px" border="0" cellspacing="0" cellpadding="0"
			style="font-size: 12px">
			<tr>
				<td align="right">檔案：</td>
				<td style="padding: 5px;"><div id="fileDataList">
						<input type="file" id="fileData" name="fileData" size="30" /><br />
					</div></td>
				<td style="padding: 5px;" colspan="2"><a href="#do"
					class="easyui-linkbutton" onClick="save($('#filesForm'));">送出</a> <a
					href="#do" class="easyui-linkbutton" onclick="window.close();">關閉</a>
				</td>
			</tr>
		</table>
	</form:form>
	<table id="tt" class="easyui-datagrid" striped="true"
		style="width: 550px; height: 600px" singleSelect="true"
		url="${appPath}/files/list.json?id=${filesForm.sessionNo}">
		<thead>
			<tr>
				<th field="filename" width="250">檔案</th>
				<th field="action" width="100" formatter="action">作業</th>
			</tr>
		</thead>
	</table>
	<form name="motionForm" id="motionForm" method="post"
		action="${appPath}/motionView/exp.htm">
		<input type="hidden" name="sessionNo" id="sessionNo"
			value="${filesForm.sessionNo}" /> <input type="hidden"
			name="fileName" id="fileName" />
	</form>

<script>
$(document).ready(function() {

});
function action(val, row, ix) {
	var o = $('#tt').datagrid('getData').rows[ix];
	var str = "[<a href=\"javascript:download('"+o.filename+"');\">下載</a>]";
	str = str.concat( "[<a href=\"javascript:doDel('" + o.filename+ "');\">刪除</a>]");
	return str;
}
function doDel(id) {
	if (confirm('確定刪除')) {
		$.post('${appPath}/files/delete.json', {
			id : id, sessionNo : '${filesForm.sessionNo}'
		}, function(data) {
			if (data) {
				$('#tt').datagrid('load');
			}
		});
	}
}
function save(formid) {
	var formData = new FormData(formid[0]);
	  $.ajax({
	    url: '${appPath}/files/save.json',
	    type: 'POST',
	    data: formData,
	    async: false,
	    cache: false,
	    contentType: false,
	    processData: false,
	    success: function (data) {
	    	$('#fileData').val('');
	    	$('#tt').datagrid('load');
	    }
	  });
}
function download(fileName) {
	$("#fileName").val(fileName);
	$("#motionForm").submit();
}
	
</script>
</body>
</html>